package util;

import java.util.Calendar;
import java.util.Date;

public class DateUtil {
    public static Date createDate(int year, int month, int date) {
        Calendar cal = Calendar.getInstance();
        cal.set(year,month-1,date);
        return cal.getTime();
    }

    public static int getWeek(int year,int month,int date){
        Calendar cal = Calendar.getInstance();
        cal.set(year,month-1,date);
        return cal.get(Calendar.DAY_OF_WEEK)-1;
    }

    public static boolean isLeapYear(int year){
        return(year%400==0) || (year%4==0 && year%100!=0);
    }

    public static int getMaxDay(int year,int month){
        int max = -1;
        if(month==1 || month ==3 || month == 5 || month==7 ||month == 8 || month == 10 || month ==12)
            max = 31;
        else if(month == 2){
            max = 28;
            max = isLeapYear(year)?29:28;
        }else{
            max = 30;
        }
        return max;
    }
}
